var app = getApp(), u = app.require("utils/util.js"), a = app.require("utils/api.js"), o = app.require("utils/onfire.js"), h = app.require("utils/http.js"), n = app.require("utils/enums");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dialogType: null,
    cateGoryList:[],
    checkIndex:1,
    secondCate:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {  
    this.getCateGory();    
  },
  onReady: function () {
   
  },
  onShow: function (options){
    var t = this;
    app.getToken();
    var index = app.globalData.value ? app.globalData.value : '118';
    t.getSecondCateById(index);
  }, 
  onClick: function (e) {
    var index = e.currentTarget.dataset.index;
    this.getSecondCateById(index);
  },  
  getCateGory:function(){
    var t = this;
    var data = {};
    h.postReq(a.getCateGoryUrl,data,function(res){
      if(res.code == 0){
        t.data.cateGoryList = res.data;
        t.setData({ cateGoryList: t.data.cateGoryList});
      }else {
        u.toast(res.message);
      }
    });
  },
  getSecondCateById: function (index){
    var t = this;
    var data = { cat_fid: index };
    h.postReq(a.getCateGoryUrl, data, function (res) {
      if (res.code == 0) {
        t.data.secondCate = res.data;
        t.setData({
          checkIndex: index,
          secondCate: t.data.secondCate
        });
      }else {
        u.toast(res.message);
      }
    });
  },
  goSearch:function(){
    wx.navigateTo({
      url: '../../category/index/list',
    })
  },
  toCateList:function(e){
    var index = e.currentTarget.dataset.index;
    var title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: 'list?group_id=' + index + '&title=' + title
    })
  }, 


})